using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EngineGame;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using WarsOnRiceFields.Object;
namespace WarsOnRiceFields
{
    public class GamePlayScreen:GameScreen
    {
        private List<Items> listItem;
        private Texture2D background;
        private Screw screw;

        //Sprite enemies
        private Sprite sScrew;
        public GamePlayScreen()
        {
        }

        public GamePlayScreen(List<Items> listItem)
        {
            this.listItem = listItem;
        }

        public void Reset()
        {
            for (int i = 0; i < listItem.Count; i++)
                listItem[i].setLocation(50 + i * 80, 410);
            screw = new Screw(100, 100,sScrew);
        }

        public override void LoadContent()
        {
            background = ScreenManager.Game.Content.Load<Texture2D>("Images/background");
            sScrew = new Sprite(ScreenManager.Game.Content, "Enimes/sOc", 4);
            Reset();
        }

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
            screw.Update(gameTime);
            foreach (Items item in listItem)
            {
                item.Update(gameTime);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(background, new Vector2(0, 0), Color.White);
            screw.Draw(ScreenManager.SpriteBatch);
            if (listItem == null)
                return;
            foreach (Items item in listItem)
            {
                item.Draw(ScreenManager.SpriteBatch);
            }
            ScreenManager.SpriteBatch.End();
            base.Draw(gameTime);
        }
        public override void HandleInput(InputState input)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (input.PauseGame)
            {
                ScreenManager.AddScreen(new Menu());
                this.ExitScreen();
                return;
            }
            TouchCollection touchState = TouchPanel.GetState();
            if (touchState.Count > 0)
            {
                foreach (Items item in listItem)
                {
                    if (item.currentTimeLoad >= item.timeLoad && item.OnSelected(touchState[0]))
                    {
                        item.currentTimeLoad = 0;
                    }
                }
            }

        }
    }
}
